package com.swallow.auth.application.api.dept;

import com.swallow.auth.api.dept.IDepartmentFacade;
import com.swallow.auth.api.dept.dto.CreateDeptDTO;
import com.swallow.auth.api.dept.dto.DeptQryReqDTO;
import com.swallow.auth.api.dept.dto.DeptQryRespDTO;
import com.swallow.auth.application.bo.dept.DeptQryRetBO;
import com.swallow.auth.application.convert.dept.CvtDeptAppMapper;
import com.swallow.auth.application.repository.dept.IDeptAppRepository;
import com.swallow.auth.common.result.R;
import com.swallow.auth.common.result.Result;
import com.swallow.auth.common.result.RetPageDTO;
import com.swallow.auth.common.utils.GsonUtil;
import com.swallow.auth.domain.dept.model.DeptRoot;
import com.swallow.auth.domain.dept.model.entity.DeptEntity;
import com.swallow.auth.domain.dept.service.IDeptDomainService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 18310740596@163.com
 * @date: 2024-05-20 21:52:16
 * @version: v1.0
 * @describe: class responsibility
 */
@Slf4j
@RestController
public class DepartmentFacadeImpl implements IDepartmentFacade {
    @Resource private IDeptDomainService deptDomainService;

    @Resource private IDeptAppRepository deptAppRepository;

    @Override
    public Result<String> create(CreateDeptDTO createDept) {
        log.info("创建部门::: 请求参数:{}", GsonUtil.toJson(createDept));

        DeptEntity deptEntity = CvtDeptAppMapper.INSTANCE.deptDTO2Entity(createDept);

        String deptNo = deptDomainService.createDept(DeptRoot.builder().deptEntity(deptEntity).build());

        log.info("创建部门::: 部门创建完成, 部门编号:{}", deptNo);
        return R.success(deptNo);
    }

    @Override
    public Result<Void> delete(String deptNo) {
        return null;
    }

    @Override
    public Result<Void> update(CreateDeptDTO createDept) {
        return null;
    }

    @Override
    public Result<RetPageDTO<DeptQryRespDTO>> listDept(DeptQryReqDTO pageQry) {
        return null;
    }

    @Override
    public Result<DeptQryRespDTO> getDept(String deptNo) {
        DeptQryRetBO retBO = deptAppRepository.getDeptByNo(deptNo);
        return R.success(CvtDeptAppMapper.INSTANCE.deptBO2DTO(retBO));
    }
}
